﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AutoGear.BLL;
using Entity;

public partial class admin_admin_cms : SiteAdminBasePage
{
    protected int cmsID = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Int32.TryParse(Request.QueryString["cmsid"], out cmsID))
            {
                LoadCMSContent(cmsID);
            }
        }        
    }

    private void LoadCMSContent(int cmsID)
    {
        TblCMS cms = TblCMS.GetTblCMSByCmsId(cmsID);
        Literal litPageTitle = (Literal)Master.FindControl("litPageTitle");
        litPageTitle.Text = cms.CmsTitle;
        txtCmsTitle.Text = cms.CmsTitle;
        //hidCKEDitorValue.Value = cms.CmsContent;
        fckContent.Value = cms.CmsContent;
    }

    protected void Create_Click(object sender, EventArgs e)
    {
        try
        {
            Int32.TryParse(Request.QueryString["cmsid"], out cmsID);

            if (cmsID != 0)
            {
                TblCMS cms = TblCMS.GetTblCMSByCmsId(cmsID);

                cms.CmsTitle = txtCmsTitle.Text;
                cms.CmsContent = fckContent.Value;
                //cms.CmsContent = hidCKEDitorValue.Value.Trim();
                cms.Save();
                uccResponseMessage.SetSuccessMessage(cms.CmsTitle + " updated");
            }
            else
            {
                uccResponseMessage.SetFailMessage("Failed");
            }
        }
        catch(Exception ex)
        {
            uccResponseMessage.SetFailMessage("Failed");
        }
    }
}
